#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7, LOGN = 19;

int fa[N][LOGN], dep[N];

int testid, n, X = 1, Y = 1, Z = 1;

inline int LCA(int x, int y) {
    if (dep[x] < dep[y])
        swap(x, y);

    for (int h = dep[x] - dep[y]; h; h &= h - 1)
        x = fa[x][__builtin_ctz(h)];
    
    if (x == y)
        return x;
    
    for (int i = LOGN - 1; ~i; --i)
        if (fa[x][i] != fa[y][i])
            x = fa[x][i], y = fa[y][i];
    
    return fa[x][0];
}

inline int dist(int x, int y) {
    return dep[x] + dep[y] - dep[LCA(x, y)] * 2;
}

inline int getdis(int u) {
    int lca = LCA(X, Y);
    return LCA(u, lca) == lca ? min(dist(LCA(X, u), u), dist(LCA(Y, u), u)) : dist(u, lca);
}

inline void update(int u) {
    if (dist(X, u) < dist(Y, u))
        swap(X, Y);
    
    if (dist(X, u) > dist(X, Y))
        swap(u, Y);
    
    if (getdis(Z) < getdis(u))
        swap(u, Z);
}

signed main() {
    freopen("forest.in", "r", stdin);
    freopen("forest.out", "w", stdout);
    scanf("%d%d", &testid, &n);
    dep[1] = 1;
    
    for (int u = 2, lstans = 0; u <= n; ++u) {
        int x;
        scanf("%d", &x);
        dep[u] = dep[fa[u][0] = x ^ lstans] + 1;
    
        for (int i = 1; i < LOGN; ++i)
            fa[u][i] = fa[fa[u][i - 1]][i - 1];
        
        update(u);
        printf("%d\n", lstans = dist(X, Y) + max(0, getdis(Z) - 1));
    }
    
    return 0;
}

